var id = getQueryParms('id');
var vum = new Vue({
    el: '#app',
    data: {
        artList: '',
        //文章列表
        typeList: '',
        //类型列表
        hotList: '',
        //热门文章
        all: 0,
        //总页数
        cur: 1,
        //当前页码
        psize: 5,
        //每页显示数量
    },
    methods: {
    	btnClick: function(data) { //页码点击事件
            if (data != this.cur) {
                this.cur = data;
                this.getData();
            }
        },
        pageClick: function() {
            this.getData();
            console.log('现在在' + this.cur + '页');
        },
        getData: function() {
            var _self = this;
            $.ajax({
                type: 'GET',
                url: reqHost + '/v1/article/index?id='+id+'&page=' + this.cur + '&psize=' + this.psize + '&order=desc&sort=id',
                success: function(data) {
                    _self.artList = data.rows;
                    _self.all = Math.ceil(data.total / _self.psize);
                    console.log(data.tatol);
                },
                error: function(data) {
                    console.log("读取jsonName error!");
                }
            });
        },
        getType: function() {
            var _self = this;
            $.ajax({
                type: 'GET',
                url: reqHost + '/v1/arttype/index',
                success: function(data) {
                    _self.typeList = data;
                    console.log(data);
                },
                error: function(data) {
                    console.log("读取jsonName error!");
                }
            });
        },
        getHot: function() {
            var _self = this;
            $.ajax({
                type: 'GET',
                url: reqHost + '/v1/article/hotlist',
                success: function(data) {
                    _self.hotList = data;
                    console.log(data);
                },
                error: function(data) {
                    console.log("读取jsonName error!");
                }
            });
        },
    },
    //计算页码属性
    computed: {
        indexs: function() {
            var left = 1;
            var right = this.all;
            var ar = [];
            if (this.all >= 5) {
                if (this.cur > 3 && this.cur < this.all - 2) {
                    left = this.cur - 2;
                    right = this.cur + 2;
                } else {
                    if (this.cur <= 3) {
                        left = 1;
                        right = 5;
                    } else {
                        right = this.all;
                        left = this.all - 4;
                    }
                }
            }
            while (left <= right) {
                ar.push(left);
                left++;
            }
            return ar;
        }
    }
});
vum.getData();
vum.getType();
vum.getHot();